package com.ivo.activiti.hr.service;

import com.ivo.activiti.dao.Dao;
import com.ivo.activiti.hr.entity.Department;
import com.ivo.activiti.hr.entity.Employee;
import com.ivo.activiti.hr.entity.Position;
import com.ivo.activiti.hr.entity.Responsibility;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author wj
 * @version 1.0
 */
@Service
public class HrServiceImpl implements HrService {

    @Resource
    private Dao dao;

    @Override
    public Employee getEmp(String empID) {
        return dao.getObject(Employee.class, empID);
    }

    @Override
    public Department getDept(String deptID) {
        return dao.getObject(Department.class, deptID);
    }

    public List<Employee> getEmpByPosition(String position){
        String[] properties = new String[] {"validFlag", "position"};
        Object[] values = new Object[] {true, position};
        List<Responsibility> responsibilityList = dao.find(Responsibility.class, properties, values);
        List<Employee> employeeList = new ArrayList<>();
        for(Responsibility responsibility: responsibilityList) {
            employeeList.add(responsibility.getEmployee());
        }
        return employeeList;
    }

    @Override
    public Position getPosition(String positionId) {
        return dao.getObject(Position.class, positionId);
    }
}
